package reflect;

import java.lang.reflect.Constructor;

/**
 * 使用指定的构造器实例化对象
 */
public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");

        //获取无参构造器
        Constructor constructor = cls.getConstructor();
        Object obj = constructor.newInstance();
        System.out.println(obj);


        //获取String参构造器
        Constructor constructor1 = cls.getConstructor(String.class);
        Object obj1 = constructor1.newInstance("cjc");
        System.out.println(obj1);


        //获取String+int参数器
        Constructor constructor2 = cls.getConstructor(String.class,int.class);
        Object obj2 = constructor2.newInstance("cjc",18);
        System.out.println(obj2);






    }
}
